//right_top
$(function() {
    var myChart = echarts.init(document.getElementById('right_top'));
    var seriesData = {
        ynsrk: { //益农社人口
            fg: 608, //覆盖
            wfg: 32 //未覆盖
        },
        qgds: { //全国地市
            fg: 22, //覆盖
            wfg: 7 //未覆盖
        },
        qgxc: { //全国乡村
            fg: 30, //覆盖
            wfg: 7 //未覆盖
        },
        ynsfgl: { //益农社覆盖率
            fg: 40, //覆盖
            wfg: 7 //未覆盖
        },
    };
    var ynsrkFgl = (seriesData.ynsrk.fg / (seriesData.ynsrk.fg + seriesData.ynsrk.wfg) * 100).toFixed(2) + '%';
    var qgdsFgl = (seriesData.qgds.fg / (seriesData.qgds.fg + seriesData.qgds.wfg) * 100).toFixed(2) + '%';
    var qgxcFgl = (seriesData.qgxc.fg / (seriesData.qgxc.fg + seriesData.qgxc.wfg) * 100).toFixed(2) + '%';
    var ynsfglFgl = (seriesData.ynsfgl.fg / (seriesData.ynsfgl.fg + seriesData.ynsfgl.wfg) * 100).toFixed(2) + '%';

    option = {
        title: {
            text: '益农社地区覆盖率统计',
            x: 'left',
            y: 'top',
            itemGap: 20,
            textStyle: {
                color: '#fff',
                fontFamily: '微软雅黑',
                fontSize: 14,
                fontWeight: 'normal'
            }
        },
        graphic: {
            elements: [
                { type: 'line' }
            ]
        },
        color: [
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#04DFE8' }, { offset: 1, color: '#0DF0B3' }], false),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#06E9EE' }, { offset: 1, color: '#41A7FE ' }], false),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#C4DD0F' }, { offset: 1, color: '#0EC30D' }], false),
            new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#F86A79' }, { offset: 1, color: '#FF3A66' }], false),
        ],
        tooltip: {
            show: true,
            formatter: "{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'horizontal',
            itemGap: 15,
            textStyle: {
                color: '#fff',
                fontSize: 12,
            },
            right: -5,
            top: '28%',
            itemWidth: 10,
            itemHeight: 12,
        },
        series: [{
                name: '益农社人口',
                type: 'pie',
                clockWise: false,
                radius: [60, 70],
                center: ['30%', '55%'],
                hoverOffset: 3,
                itemStyle: {
                    normal: {
                        label: { show: false },
                        labelLine: { show: false }
                    }
                },
                data: [{
                        value: seriesData.ynsrk.fg,
                        name: '益农社人口 ' + ynsrkFgl,
                    },
                    {
                        value: seriesData.ynsrk.wfg,
                        name: '',
                        itemStyle: {
                            normal: {
                                color: 'rgba(0,0,0,0)',
                                label: { show: false },
                                labelLine: { show: false }
                            },
                            emphasis: {
                                color: 'rgba(0,0,0,0)'
                            }
                        }
                    }
                ]
            },
            {
                name: '全国地市',
                type: 'pie',
                clockWise: false,
                radius: [45, 55],
                center: ['30%', '55%'],
                hoverOffset: 3,
                itemStyle: {
                    normal: {
                        label: { show: false },
                        labelLine: { show: false }
                    }
                },
                data: [{
                        value: seriesData.qgds.fg,
                        name: '全国地市 ' + qgdsFgl
                    },
                    {
                        value: seriesData.qgds.wfg,
                        name: '',
                        itemStyle: {
                            normal: {
                                color: 'rgba(0,0,0,0)',
                                label: { show: false },
                                labelLine: { show: false }
                            },
                            emphasis: {
                                color: 'rgba(0,0,0,0)'
                            }
                        }
                    }
                ]
            },
            {
                name: '全国乡村',
                type: 'pie',
                clockWise: false,
                radius: [30, 40],
                center: ['30%', '55%'],
                hoverOffset: 3,
                itemStyle: {
                    normal: {
                        label: { show: false },
                        labelLine: { show: false }
                    }
                },
                data: [{
                        value: seriesData.qgxc.fg,
                        name: '全国乡村 ' + qgxcFgl
                    },
                    {
                        value: seriesData.qgxc.wfg,
                        name: '',
                        itemStyle: {
                            normal: {
                                color: 'rgba(0,0,0,0)',
                                label: { show: false },
                                labelLine: { show: false }
                            },
                            emphasis: {
                                color: 'rgba(0,0,0,0)'
                            }
                        }
                    }
                ]
            },
            {
                name: '益农社覆盖率',
                type: 'pie',
                clockWise: false,
                radius: [15, 25],
                center: ['30%', '55%'],
                hoverOffset: 3,
                itemStyle: {
                    normal: {
                        label: { show: false },
                        labelLine: { show: false }
                    }
                },
                data: [{
                        value: seriesData.ynsfgl.fg,
                        name: '益农社覆盖率 ' + ynsfglFgl,
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#F86A79' }, { offset: 1, color: '#FF3A66' }], false),
                                label: { show: false },
                                labelLine: { show: false }
                            },
                        }
                    },
                    {
                        value: seriesData.ynsfgl.wfg,
                        name: '',
                        itemStyle: {
                            normal: {
                                color: 'rgba(0,0,0,0)',
                                label: { show: false },
                                labelLine: { show: false }
                            },
                            emphasis: {
                                color: 'rgba(0,0,0,0)'
                            }
                        }
                    }
                ]
            },
        ]
    };
    myChart.setOption(option);
});
// #zdjsywc
$(function() {
    var myChart = echarts.init(document.getElementById('zdjsywc'));
    var seriesData = {
        jyz: { //简易站
            yjc: 5556, //已建成
            dj: 1000 //代建
        },
        bzz: { //标准站
            yjc: 9889, //已建成
            dj: 1000 //代建
        },
        zyz: { //专业站
            yjc: 2189, //已建成
            dj: 200 //代建
        },
    };
    var option = {
        title: [{
                text: '简易站' + seriesData.jyz.yjc,
                textStyle: {
                    color: '#fff',
                    fontSize: 12,
                },
                bottom: '6%',
                left: '3.8%',


            },
            {
                text: '标准站' + seriesData.bzz.yjc,
                textStyle: {
                    color: '#fff',
                    fontSize: 12,
                },
                bottom: '6%',
                left: '39.2%',


            },
            {
                text: '专业站' + seriesData.zyz.yjc,
                textStyle: {
                    color: '#fff',
                    fontSize: 12,
                },
                bottom: '6%',
                left: '74%',


            }
        ],
        legend: {
            show: false
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        series: [{
                name: '简易站',
                type: 'pie',
                radius: ['42%', '62%'],
                center: ['15%', '40%'],
                startAngle: 50,
                avoidLabelOverlap: false,
                hoverOffset: 3,
                labelLine: {
                    show: false
                },
                data: [{
                    value: seriesData.jyz.yjc,
                    name: '已建成',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#e1e113' }, { offset: 1, color: '#e16d14' }], false)
                    },
                    label: {
                        show: true,
                        color: '#fff',
                        position: 'center',
                        formatter: '{d}%'
                    }
                }, {
                    value: seriesData.jyz.dj,
                    name: '代建',
                    itemStyle: {
                        color: '#364B7B'
                    },
                    label: {
                        show: false,
                    }
                }, ],
            },
            {
                name: '标准站',
                type: 'pie',
                radius: ['42%', '62%'],
                center: ['50%', '40%'],
                startAngle: 50,
                avoidLabelOverlap: false,
                hoverOffset: 3,
                labelLine: {
                    show: false
                },
                data: [{
                    value: seriesData.bzz.yjc,
                    name: '已建成',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#0dd6e2' }, { offset: 1, color: '#3f9aea' }], false)
                    },
                    label: {
                        show: true,
                        color: '#fff',
                        position: 'center',
                        formatter: '{d}%'
                    }
                }, {
                    value: seriesData.bzz.dj,
                    name: '代建',
                    itemStyle: {
                        color: '#364B7B'
                    },
                    label: {
                        show: false,
                    }
                }, ]
            },
            {
                name: '专业站',
                type: 'pie',
                radius: ['42%', '62%'],
                center: ['85%', '40%'],
                startAngle: 50,
                avoidLabelOverlap: false,
                hoverOffset: 3,
                labelLine: {
                    show: false
                },
                data: [{
                        value: seriesData.zyz.yjc,
                        name: '已建成',
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#8ADE0F' }, { offset: 1, color: '#1EBA66' }], false)
                        },
                        label: {
                            show: true,
                            color: '#fff',
                            position: 'center',
                            formatter: '{d}%'
                        }
                    }, {
                        value: seriesData.zyz.dj,
                        name: '代建',
                        itemStyle: {
                            color: '#364B7B'
                        },
                        label: {
                            show: false,
                        }
                    },

                ]
            },

        ]
    };
    myChart.setOption(option);
});
// #left_bottom
$(function() {
    var myChart = echarts.init(document.getElementById('left_bottom'));
    var data = [
        { name: '新增商品', value: 421561 },
        { name: '库存警告', value: 202330 },
        { name: '新品推荐', value: 462875 },
        { name: '特价推荐', value: 182220 },
        { name: '活动商品', value: 401561 },
        { name: '已下架商品', value: 333333 }
    ];
    var yAxisData = new Array();
    var seriesData = new Array();
    for (var i = 0; i < data.length; i++) {
        yAxisData.push(data[i].name);
        seriesData.push({
            value: data[data.length - i - 1].value,
            itemStyle: {
                barBorderRadius: 100,
                color: new echarts.graphic.LinearGradient(
                    1, 1, 0, 1, [
                        { offset: 0, color: '#00d8ff' },
                        { offset: 1, color: '#0df0b3' },
                    ]
                )
            },
            label: {
                show: true,
                color: '#00d8ff',
                position: 'right',
                fontSize: 12,
                formatter: function(params) {
                    var val = params.value;
                    return val;
                }
            }
        });
    }
    yAxisData.reverse();
    var option = {
        title: {
            text: '',
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            show: false
        },
        grid: {
            left: '5%',
            right: '20%',
            bottom: '12%',
            top: '5%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            name: '单位 : 千件',
            nameTextStyle: {
                color: '#fff',
                fontSize: 12
            },
            nameGap: 30,
            nameLocation: 'center',
            axisLine: {
                show: true,
                lineStyle: {
                    color: '#4b607a',
                    width: 2,
                }
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                show: true,
                color: '#a6b8cb',
                formatter: function(value, index) {
                    return value / 1000;
                }
            },
            splitLine: {
                show: false,
            }
        },
        yAxis: {
            type: 'category',
            data: yAxisData,
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                color: '#e8e8e8',
                fontSize: 12
            }
        },
        series: [{
            type: 'bar',
            data: seriesData,
            barWidth: '50%',
        }]
    };


    myChart.setOption(option);
});
//滚动
$(function() {
    $('#gy_box').niceScroll({
        cursorcolor: "#518bd2", //#CC0071 光标颜色
        cursoropacitymax: 1, //改变不透明度非常光标处于活动状态（scrollabar“可见”状态），范围从1到0
        touchbehavior: false, //使光标拖动滚动像在台式电脑触摸设备
        cursorwidth: "5px", //像素光标的宽度
        cursorborder: "0", //   游标边框css定义
        cursorborderradius: "5px", //以像素为光标边界半径
        autohidemode: false //是否隐藏滚动条
    });
});
//滑动
$(function() {
    $(".gdssj_info li").each(function(i, v) {
        if (i % 2 != 0) {
            $(v).addClass("even");
        }
    })
    var doscroll1 = function() {
        var $parent = $('.gdssj_info');
        var $first = $parent.find('li:first');
        var height = $first.height();
        $first.animate({
            height: 0
        }, 500, function() {
            if ($(".gdssj_info li").length % 2 != 0) {
                $first.toggleClass('even');
            }
            $first.css('height', height).appendTo($parent);
        });
    };
    setInterval(function() { doscroll1() }, 3000);
});

//map_area
$(function() {

    var map = new T.Map('allmap', {
        attributionControl: false,
        inertia: false,
        minZoom: 6,
        maxZoom: 14
    });
    var lng = 114.556458; //浚县
    var lat = 35.681213; //浚县
    map.centerAndZoom(new T.LngLat(113.634632, 33.937912), 7)


    map.addEventListener("click", function() {
        map.closeInfoWindow();
        $("#nearInfo").css("display", "none");
    });
    var dataArr = data.cjfwzList;
    var markers = new T.MarkerClusterer(map, {});

    //创建图片对象:
    function createIcon(leibie) {
        var url;
        if (leibie == 0) {
            url = "images/j.png"
        } else if (leibie == 1) {
            url = "images/b.png"
        } else if (leibie == 2) {
            url = "images/z.png"
        } else {
            url = "images/m.png"
        }
        var icon = new T.Icon({
            iconUrl: url,
            iconSize: new T.Point(35, 25)
        });
        return icon;
    }

    function moveendFun() {
        var arrayObj = new Array();
        var bs = map.getBounds();
        var bssw = bs.getSouthWest();
        var bsne = bs.getNorthEast();
        for (var i = 0; i < dataArr.length; i++) {
            var lng = dataArr[i].x;
            var lat = dataArr[i].y;
            var leibie = dataArr[i].fenlei;
            if (lat >= bssw.lat && lat <= bsne.lat && lng >= bssw.lng && lng <= bsne.lng) {
                var point = new T.LngLat(lng, lat);
                var marker = new T.Marker(point, {
                    icon: createIcon(leibie)
                });
                addClickHandler(dataArr[i], marker);

                arrayObj.push(marker);
                dataArr.splice(i, 1);
            }
        }
        markers.addMarkers(arrayObj);
    };

    moveendFun();

    map.addEventListener('moveend', moveendFun);

    function autoRender() {
        var arrayObj = new Array();
        if (dataArr.length == 0) {
            clearInterval(interval_id);
        }
        for (var i = 0; i < 4000; i++) {
            if (dataArr[i]) {
                var lng = dataArr[i].x;
                var lat = dataArr[i].y;
                var leibie = dataArr[i].fenlei;
                var point = new T.LngLat(lng, lat);
                var marker = new T.Marker(point, {
                    icon: createIcon(leibie)
                });
                addClickHandler(dataArr[i], marker);
                arrayObj.push(marker);
                dataArr.splice(i, 1);
            }
        };
        markers.addMarkers(arrayObj);
    };

    // var interval_id = setInterval(autoRender, 1000);//自动渲染;

    //点击事件;
    function addClickHandler(da, marker) {
        marker.addEventListener("click", function(e) {

            var lng = e.lnglat.lng;
            var lat = e.lnglat.lat;


            var data = {
                cjfwz: {
                    phone: 18312505555,
                    address: '郑州市郑东新区CBD',
                    xxy: '小明'
                }
            };
            var infoWin1 = '';
            var xxy = data.cjfwz.xxy;
            var phone = '联系电话:' + data.cjfwz.phone;
            var address = '地址：' + data.cjfwz.address;
            var banner = '';
            if (data != null) {
                var centent = "<div style='padding-top:5px;'>" + '信息员：' + xxy + '&nbsp;&nbsp;<br/>' + phone + '<br/>' + address + "<br/></br></div>" + "<div align='center'  style=' position:relative;bottom:10px;'><a href='#' style='color:blue;'>查看村站</a></div>";
                infoWin1 = new T.InfoWindow(centent, {
                    offset: new T.Point(0, -10),
                }) // 创建信息窗口对象 
            }
            map.openInfoWindow(infoWin1, new T.LngLat(lng, lat)) //开启信息窗口   
            $('.tdt-infowindow-close-button').on('click', function() {
                $("#nearInfo").css("display", "none");
            })
           
        });
    }
});